#!/usr/bin/env bash

if [[ ! -d "./target" ]]; then
    mkdir ./target
    echo "mkdir target success!"
fi

rm -rf ./target/*
echo "clear dir target sucess"
cp -r ./src ./target/agent
yes | cp -i ./src/config/config-prod.js ./target/agent/config/config.js
yes | cp -i ./src/const-prod.js ./target/agent/const.js
yes | cp -i ./src/config/redis-prod.json ./target/agent/config/redis.json
yes | cp -i ./src/config/session-prod.json ./target/agent/config/session.json
rm ./target/agent/config/config-prod.js
rm ./target/agent/config/config-test.js
rm ./target/agent/config/config-gprod.js
rm ./target/agent/config/redis-prod.json
rm ./target/agent/config/redis-test.json
rm ./target/agent/config/session-prod.json
rm ./target/agent/config/session-test.json

echo ""
echo "cp src to target agent success!"

cd ./target
echo "cd dir target:"
pwd
tar -cvf ./agent.tar.gz ./agent
rm -rf ./agent
echo "package agent success!"